/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import Utilitarios.TamanhoMaximoTextField;
import dao.FuncionarioDAO;
import dao.PessoaDAO;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import model.Funcionario;
import model.Pessoa;
import static view.fPrincipal.getPanel;

/**
 *
 * @author brunorafael
 */
public class LoginView extends javax.swing.JDialog {

    public static fPrincipal CadFiliado;
    private static String usuario;

    public static void setUsuario(String usuario) {
        LoginView.usuario = usuario;
    }

    public static String getUsuario() {
        return usuario;
    }
    /*
     * Creates new form LoginView
     */

    public LoginView(fPrincipal parent, boolean modal) {

        this.CadFiliado = parent;
        this.setModal(modal);

        initComponents();
        EtLogin.setDocument(new TamanhoMaximoTextField(20));
        EtSenha.setDocument(new TamanhoMaximoTextField(20));
        Color minhaCor = new Color(219, 219, 217);

        getContentPane().setBackground(minhaCor);
        setLocationRelativeTo(null);
//        parent.fechaInternalFrames();
//        TesteInternal ti = new TesteInternal();
//        parent.addTelaDesk(ti);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        EtLogin = new javax.swing.JTextField();
        BtLogin = new javax.swing.JButton();
        BTSair = new javax.swing.JButton();
        EtSenha = new javax.swing.JPasswordField();
        jLabel5 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setBackground(new java.awt.Color(219, 219, 217));
        setBounds(new java.awt.Rectangle(0, 0, 0, 0));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setFocusTraversalPolicyProvider(true);
        setMaximumSize(new java.awt.Dimension(640, 460));
        setMinimumSize(new java.awt.Dimension(640, 450));
        setPreferredSize(new java.awt.Dimension(640, 460));
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
        getContentPane().add(EtLogin, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 220, 195, -1));

        BtLogin.setText("Entrar");
        BtLogin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtLoginActionPerformed(evt);
            }
        });
        getContentPane().add(BtLogin, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 300, 76, 31));

        BTSair.setText("Sair");
        BTSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTSairActionPerformed(evt);
            }
        });
        getContentPane().add(BTSair, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 300, 74, 31));
        getContentPane().add(EtSenha, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 260, 195, -1));

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(255, 255, 255));
        jLabel5.setText("Senha:");
        getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 260, 50, 20));

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("Login:");
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 220, 50, 20));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/telaLogin_1.jpg"))); // NOI18N
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 690, 440));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private boolean validacaoDosCampos() {
        FuncionarioDAO pdao = new FuncionarioDAO();
        List<Funcionario> p = new ArrayList<Funcionario>();
        p = pdao.findAll2();
        boolean val;

        if (EtLogin.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "Campo USUÁRIO está em branco!");
            return false;
        } else if (EtSenha.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "Campo SENHA está em branco!");
            return false;
        }

        if (pdao.efetuarLogin(EtLogin.getText(), EtSenha.getText()) != null) {
            return true;
        } else {
            return false;
        }
    }

    //metodo de ação no clik do botão ENTRAR
    private void BtLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtLoginActionPerformed

        FuncionarioDAO pdao = new FuncionarioDAO();
        if (validacaoDosCampos()) {
            usuario = EtLogin.getText();
            LoginView.this.dispose();
        }
    }//GEN-LAST:event_BtLoginActionPerformed

    private void BTSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTSairActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_BTSairActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;

                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(LoginView.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(LoginView.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(LoginView.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(LoginView.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                LoginView dialog = new LoginView(CadFiliado, true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BTSair;
    private javax.swing.JButton BtLogin;
    private javax.swing.JTextField EtLogin;
    private javax.swing.JPasswordField EtSenha;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    // End of variables declaration//GEN-END:variables

    private void setMaximizedBounds(Rectangle rectangle) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    /**
     * @return the logado
     *
     *
     */

}
